package com.cheung.leetcode.day;

import  org.junit.jupiter.api.Test;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.day
 * @Author :  cheungming
 * @CreateTime : 2024-07-03 18:53:38
 * @Description : 每日 一题
 * @Version : 1.0
 */
public class Code3099Test {
    public int sumOfTheDigitsOfHarshadNumber(int x) {
        int sum = 0;
        int n = x;
        while (n > 0) {
            sum += n % 10;
            n = n / 10;
        }
        return x % sum == 0 ? sum : -1;
    }

    @Test
    public void test1() {
        assert sumOfTheDigitsOfHarshadNumber(18) == 9;
    }

    @Test
    public void test2() {
        assert sumOfTheDigitsOfHarshadNumber(23) == -1;
    }
}
